package com.at.util;

import org.springframework.beans.BeanWrapperImpl;

import java.beans.PropertyDescriptor;
import java.util.ArrayList;

/**
 * @author : code1997
 * @date :2020-10-2020/10/14 21:18
 */
public class MyBeanUtils {

    public static String[] getNUllPropertyNames(Object source){
        BeanWrapperImpl beanWrapper = new BeanWrapperImpl(source);
        PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors();
        ArrayList<Object> nullPorpertyNames = new ArrayList<>();
        for (PropertyDescriptor pd : propertyDescriptors) {
            String propertyName = pd.getName();
            if (beanWrapper.getPropertyValue(propertyName)==null){
                nullPorpertyNames.add(propertyName);
            }
        }
        return nullPorpertyNames.toArray(new String[nullPorpertyNames.size()]);
    }
}
